package com.qyhl.webtv.module_news.news.titlenews;

import android.util.Log;

import com.google.gson.Gson;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.basiclib.utils.network.model.ApiResult;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.module_news.common.NewsUrl;

/**
 * Created by qyhl on 2017/11/24.
 */

public class TitleNewsModel implements TitleNewsContract.TitleNewsModel {
    private TitleNewsPresenter mPresenter;

    public TitleNewsModel(TitleNewsPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    /**
     * 点击数统计
     * @param newsId
     */
    @Override
    public void count(String newsId) {

        EasyHttp.get(NewsUrl.GET_NEWS_DETAIL_COUNT)
                .params("newsId", newsId)
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .params("siteId", String.valueOf(CommonUtils.getInstance().getSite()))
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {

                    }

                    @Override
                    public void onSuccess(String s) {
                        ApiResult apiResult = new Gson().fromJson(s,ApiResult.class);
                        if (apiResult.getCode() == 200) {
                            Log.i("count", "count success");
                        } else {
                            Log.i("count", "count error");
                        }
                    }
                });

    }
}
